<template>
    <div class="w-full h-full bg-gray-100">
        <p class="p-[5px]">打印选项</p>
        <div class="flex text-sm justify-around mt-[50px] text-blue-500">
            <div>
                零件类别:
                <el-select v-model="type" placeholder="请选择类别" style="width: 160px">
                    <el-option v-for="item in totalstore.printOption" :key="item" :label="item" :value="item" />
                </el-select>
            </div>
            <div>
                选择顺序号从
                <el-input-number v-model="num1" />
                到
                <el-input-number v-model="num2" />
            </div>
            <el-button style="background-color: #999; color: white;" @click="starPrint" type="info" plain>打印</el-button>
        </div>
    </div>
</template>
<script setup lang='js' name='MMainPrint'>
import { useRouter } from 'vue-router'
const router = useRouter()
// 在store中获取打印的选项数据
import {useTotalStore}from '@/stores/total'
const totalstore = useTotalStore()

// 生成发货单pinia库
import { useDispatchlistStore } from "@/stores/dispatchList"
const dispatchlistStore = useDispatchlistStore()
// 获取二维码pinia库
import { useQrcodeStore } from "@/stores/qrcode"
const qrcodeStore = useQrcodeStore()
// import { getQrcode } from "../api/fis"
import { ref } from 'vue'
let type = ref('顶棚')
let num1 = ref()
let num2 = ref()
function getCurrentTime(format = 'datetime', locale = undefined) {
    const now = new Date();
    switch (format) {
        case 'timestamp':
            return now.getTime(); // 返回时间戳（毫秒）
        case 'date':
            return now.toISOString().split('T')[0]; // 返回日期部分：YYYY-MM-DD
        case 'time':
            return now.toTimeString().split(' ')[0]; // 返回时间部分：HH:MM:SS
        case 'locale':
            return now.toLocaleString(locale); // 返回本地化格式
        case 'datetime':
        default:
            // 返回默认格式：YYYY-MM-DD HH:MM:SS
            return `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')} ${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}:${String(now.getSeconds()).padStart(2, '0')}`;
    }
}
// 二维码
// const test = async () => {
//     let res = await getQrcode("9a813c39-fd55-47c2-8259-f581fbbce3c2")
//     console.log(res.data);

// }
function starPrint() {
    const data = {
        "startSeq": num1.value,
        "endSeq": num2.value,
        "partTypeId": type.value === '顶棚' ? 6 : undefined
    }

    dispatchlistStore.funDispatchList(data)
        .then(async () => {
            await qrcodeStore.funGetQrcode(dispatchlistStore.uuid)
            router.push({
                path: "/print",
                query: {
                    data: getCurrentTime(),
                    // qrcode: qrcodeStore.qrcodeData
                }
            })
        })
}

</script>
